#include <iostream>

using std::cout;
using std::endl;

//1、不管以什么继承方式，对于基类中的私有成员在派生类中都是不能直接访问的
//2、不管以什么继承方式，对于基类中的非私有成员在派生类中都是可以直接访问的
//3、不管以什么继承方式，对于派生类对象而言，只能访问公有继承基类中的公有成员
//其他都全部都不能访问

struct Point
{
/* public://公有的 */
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int, = 0, int = 0)" << endl;
    }

    void print() const
    {
        cout << "(" << _ix
             << ", " << _iy
             << ")" << endl;
    }

    int getY() const
    {
        return _iy;
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

/* protected://保护的 */
    int _ix;
/* private://私有的 */
    int _iy;
};

struct Point3D 
: Point
{
/* public: */
    Point3D(int ix = 0, int iy = 0, int iz = 0)
    //对于从基类吸收的数据成员的初始化，需要借助
    //基类的构造函数
    : Point(ix, iy)
    , _iz(iz)
    {
        cout << "Point3D(int = 0, int = 0, int = 0)" << endl;
    }

    void show() const
    {
        print();//public
        cout << "_ix = " << _ix << endl;//protected
        /* cout << "_iy = " << _iy << endl;//error */
        cout << "_iy = " << getY() << endl;//ok,public
        cout <<"_iz = " << _iz << endl;//ok,private
    }

    ~Point3D()
    {
        cout << "~Point()" << endl;
    }
/* private: */
    int _iz;
};

struct  Point4D
: Point3D
{
public:
    void show() const
    {
        print();//protected
        cout << "_ix = " << _ix << endl;//protected
        /* cout << "_iy = " << _iy << endl;//error */
        cout << "_iy = " << getY() << endl;//ok,protected
    }

};
void test()
{
    cout << "sizeof(Point) = " << sizeof(Point) << endl;//8
    cout << "sizeof(Point3D) = " << sizeof(Point3D) << endl;//4 + 8

    Point3D pt3d(1, 2, 3);
    pt3d.print();//ok
    pt3d.getY();//ok
    /* pt3d._ix;//error */
    /* pt3d._iy;//error */
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

